package cn.schoolwow.util.test.module.crypto.testcase;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.crypto.cipher.aes.AESCipher;
import cn.schoolwow.util.domain.crypto.cipher.aes.AESPaddingType;
import cn.schoolwow.util.domain.crypto.cipher.aes.AESSecretKeyType;
import org.junit.Assert;

public class AESTestCaseFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        String message = "hello,world!";

        String mode = "CBC";
        String iv = AESCipher.generateRandomIV();
        String secretKey = AESCipher.generateSecretKey(AESSecretKeyType.Key192);

        AESCipher aesCipher = AESCipher.newCipher(secretKey)
                .mode(mode)
                .iv(iv)
                .padding(AESPaddingType.PKCS5Padding.padding);
        String encryptText = aesCipher.data(message).encrypt();
        String plainText = aesCipher.data(encryptText).decrypt();
        Assert.assertEquals(message, plainText);
    }

    @Override
    public String name() {
        return "AES算法测试用例";
    }
}
